<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Messenger/classes/PhpFox_ComponentInbox.class.php, $Author:  $ */



/** User inbox compoenent.
 *
 * @package module.messenger
 * @version $Id:
 *   PHPFox Team ()
 */
class PhpFox_Mod_Messenger_ComponentInbox extends BaseComponent
{
    /** Processing method
     */
    function process()
    {
        $oReq = &App::getRequest();
        $oSrvMessenger = $this->_oModule->getService('Messenger');

        $oSrvAccount = &App::getModuleService('Account', 'Security');
        $aCond = array();
        $iPage = $oReq->get('page', 1);
        $iPageSize = App::getParam('public.pagesize');

        switch ($oReq->get('box'))
        {
            case 'sentbox':
            	$sBoxName = App::format('sentbox');
            	$aCond = array('from' => ' = "'.$oSrvAccount->getCurrentUserLogin().'"', 'type'=> '="mail"', 'is_del_sent'=>'!= '.$oSrvAccount->getUserIdByName($oSrvAccount->getCurrentUserLogin()));
            	$aDel = $oReq->getArray('id');
            	if(!empty($aDel))
                {
                	
                    $oSrvMessenger->markDel($aDel,$oSrvAccount->getUserIdByName($oSrvAccount->getCurrentUserLogin()));
                    App::gotoUrl('', array('box'=>'sentbox'), App::format('Mod_Messenger.deleted.items'));
                }
            	break;
           	default :
                $sBoxName = App::format('inbox');
                $aCond = array('to' => ' = "'.$oSrvAccount->getCurrentUserLogin().'"', 'type'=> '="mail"');
                $aCond['is_del_sent'] = '!= '.$oSrvAccount->getUserIdByName($oSrvAccount->getCurrentUserLogin());
                $aDel = $oReq->getArray('id');
                $aMemberShip = $oSrvAccount->getUserMembershipData();
                if(!$oSrvMessenger->checkInboxLimit($oSrvAccount->getCurrentUserLogin(), $aMemberShip))
                    $this->addErrors($oSrvMessenger->getErrors());
                if(!empty($aDel))
                {
                	$oSrvMessenger->markDel($aDel,$oSrvAccount->getUserIdByName($oSrvAccount->getCurrentUserLogin()));
                    App::gotoUrl('', array(), App::format('Mod_Messenger.deleted.items'));
                }
        		break;
        }

        $sOrder = 'time DESC';

        list($aMessenger, $iCnt) = $oSrvMessenger->listMessages($aCond, $iPage, $iPageSize, $sOrder);

        $oPager = App::newObject('Pager', $iCnt, $iPage, $iPageSize);

        $oTpl = &$this->_oModule->getTemplate();
        $oTpl->assignSrc(array('aErrors'		=> $this->getErrors(),));

        $oTpl->assign(array(
                             'aMessenger'   => $aMessenger,
                             'iCnt'         => $iCnt,
        				     'aPaging'      => $oPager->getInfo(App::getUrl()),
        					 'sUserPicUrl' 	=> App::getParam('user.pic.url'),
        					 'sBoxTitle' => $sBoxName,
       						 'sBoxName'		=> $oReq->get('box'),
                             'sUrlView'     => $this->getParam('url_view')
        ));

        $sHtml = $oTpl->fetch('Inbox.html');

        return $sHtml;
    }
}
?>